package sort

import (
	"fmt"
	"math/rand"
	"time"
)

type BaseSort struct {
	Array []int
}

func (self BaseSort) Sort() {
	panic("implement me")
}

func (self BaseSort) Len() int {
	return len(self.Array)
}

func (self BaseSort) Less(i, j int) bool {
	return self.Array[i] <= self.Array[j]
}

func (self BaseSort) Swap(i, j int) {
	self.Array[i], self.Array[j] = self.Array[j], self.Array[i]
}

func (self BaseSort) Name() string {
	panic("implement me")
}

func (self BaseSort) PrintArray() {
	fmt.Println(self.Array)
}

func (self *BaseSort) GenArray(len int, maxNum int) {
	if self.Array == nil {
		rand.Seed(time.Now().UnixNano())
		for i := 0; i < len; i++ {
			self.Array = append(self.Array, rand.Intn(maxNum))
		}
	}
}

func (self *BaseSort) GenStableArray() {
	//self.Array = []int{5, 4, 3, 2, 1, 0}
	self.Array = []int{10, 8, 9, 2, 5}
}

func (self BaseSort) IsSorted() bool {
	for i := 0; i < len(self.Array)-1; i++ {
		if !self.Less(i, i+1) {
			return false
		}
	}
	return true
}
